#include "fxcc/yml/Serializer.h"
#include "fxcc/core/graph/common/AnimTransition.h"

using namespace fxcc::yml;
using namespace fxcc::graph::common;

template<>
 void Serializer::Encode<AdditionChannelConfig>(YAML::Node& node, const AdditionChannelConfig& inst)
{
	SetVariable<std::string>(node, "m_ChannelName", inst.m_ChannelName);
	SetVariable<glm::ivec3>(node, "m_KeyFlag", inst.m_KeyFlag);
}


template<>
bool Serializer::Decode<AdditionChannelConfig>(const YAML::Node& node, AdditionChannelConfig& inst)
{
	GetVariable<std::string>(node, "m_ChannelName", inst.m_ChannelName);
	GetVariable<glm::ivec3>(node, "m_KeyFlag", inst.m_KeyFlag);
	return true;
}


template<>
void Serializer::Encode<AnimationNode::AdditonConfig>(YAML::Node& node, const AnimationNode::AdditonConfig& inst)
{
	SetVariable<bool>(node, "m_Looping", inst.m_Looping);
	SetVariable<float>(node, "m_AnimSpeed", inst.m_AnimSpeed);

	SetArrayVariable<AdditionChannelConfig>(node, "m_AdditionaChannelConfigs", inst.m_AdditionaChannelConfigs);
}


template<>
bool Serializer::Decode<AnimationNode::AdditonConfig>(const YAML::Node& node, AnimationNode::AdditonConfig& inst)
{
	GetVariable<bool>(node, "m_Looping", inst.m_Looping);
	GetVariable<float>(node, "m_AnimSpeed", inst.m_AnimSpeed);
	GetArrayVariable<AdditionChannelConfig>(node, "m_AdditionaChannelConfigs", inst.m_AdditionaChannelConfigs);
	return true;
}

template<>
void Serializer::Encode<AnimationNode>(YAML::Node& node, const AnimationNode& inst)
{
	Encode<fxcc::Base>(node, inst);
	SetVariable<float>(node, "m_AnimAxis", inst.m_AnimAxis);
	SetVariable<bool>(node, "m_ReachEnd", inst.m_ReachEnd);
	SetVariable<bool>(node, "m_RootMotion", inst.m_RootMotion);
	SetVariable<AnimationMap>(node, "m_AnimationMap", inst.m_AnimationMap);
	SetVariable<AnimationNode::AdditonConfig>(node, "m_AdditionConfig", inst.m_AdditionConfig);
}


template<>
bool Serializer::Decode<AnimationNode>(const YAML::Node& node, AnimationNode& inst)
{
	Decode<fxcc::Base>(node, inst);
	GetVariable<float>(node,"m_AnimAxis", inst.m_AnimAxis);
	GetVariable<bool>(node, "m_ReachEnd", inst.m_ReachEnd);
	GetVariable<bool>(node, "m_RootMotion", inst.m_RootMotion);
	GetVariable<AnimationMap>(node, "m_AnimationMap", inst.m_AnimationMap);
	GetVariable<AnimationNode::AdditonConfig>(node, "m_AdditionConfig", inst.m_AdditionConfig);

	return true;
}
